home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / interapplication comm / 7edit / source / sveditprinting.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  3.2 KB  |  117 lines

  1. /*
  2.     File:        SVEditGXPrinting.c
  3.  
  4.     Contains:    Adds GX printing functionality to 7Edit
  5.  
  6.     Written by: Original version by Jon Lansdell and Nigel Humphreys.
  7.                             3.1 updates by Greg Sutton.    
  8.  
  9.     Copyright:    Copyright ©1995-1999 by Apple Computer, Inc., All Rights Reserved.
  10.  
  11.                 You may incorporate this Apple sample source code into your program(s) without
  12.                 restriction. This Apple sample source code has been provided "AS IS" and the
  13.                 responsibility for its operation is yours. You are not permitted to redistribute
  14.                 this Apple sample source code as "Apple sample source code" after having made
  15.                 changes. If you're going to re-distribute the source, we require that you make
  16.                 it clear in the source that the code was descended from Apple sample source
  17.                 code, but that you've made changes.
  18.  
  19.     Change History (most recent first):
  20.                 7/19/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  21.                 
  22.  
  23. */
  24.  
  25. #include <Gestalt.h>
  26. #include "SVEditPrinting.h"
  27. #include "SVEditWindow.h"
  28. #include "SVEditGlobals.h"
  29. #include "SVEditMain.h"
  30.  
  31. // Constants
  32.  
  33. #define        kGraphicsHeapSize    ((long) 300 * 1024)
  34.  
  35. // Globals
  36.  
  37.  
  38.  
  39.  
  40. //-------------------------------------------------------
  41. //       GetRectOfPage
  42. //
  43. // This returns a QuickDraw rect for the current printer page.
  44. // If gx is not present if uses rPage from the document's THPrint.
  45. // If gx is present then we get a GXRectangle from the requested
  46. // page's format. It then converts this to a Rect. This could be
  47. // extended to handle custom formated pages.
  48. //-------------------------------------------------------
  49.  
  50. #pragma segment Main
  51.  
  52. void GetRectOfPage( DPtr  theDoc,
  53.                                         Rect  *pageRect )
  54. {
  55.  
  56.     *pageRect = (*(theDoc->thePrintSetup))->prInfo.rPage;
  57.     OffsetRect( pageRect, -pageRect->left, -pageRect->top);
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64. //-------------------------------------------------------
  65. //       DuplicateStyleTERec
  66. //
  67. // This copies the styled TERec in theDoc. It puts it into
  68. // the destPort
  69. //-------------------------------------------------------
  70.  
  71. #pragma segment Main
  72.  
  73. void DuplicateStyleTERec( TEHandle  hSourceTE,
  74.                                                     TEHandle *hDestTE,
  75.                                                     Rect     *destRect,
  76.                                                     GrafPtr   destPort )
  77. {
  78.     GrafPtr oldPort;
  79.     short   oldSelStart;
  80.     short   oldSelEnd;
  81.     StScrpHandle printerTextStyles;
  82.     
  83. // Set up the ports
  84.     GetPort(&oldPort);
  85.     SetPort(destPort);
  86.     
  87. // Create a temporary Text Edit and copy the windows text edit into it
  88.     *hDestTE = TEStyleNew(destRect, destRect);
  89.  
  90. // Select all the text (preserving the previous settings) so that we can use 
  91. // GetTylScrap (or TEGetStyleScrapHandle ) to get the style of the whole TERec
  92.     oldSelStart = (*hSourceTE)->selStart;
  93.     oldSelEnd   = (*hSourceTE)->selEnd;
  94.     TESetSelect(0,(*hSourceTE)->teLength, hSourceTE);
  95.  
  96. // Get the style
  97.     printerTextStyles = TEGetStyleScrapHandle(hSourceTE);
  98.  
  99. // Revert the selection range
  100.     TESetSelect(oldSelStart, oldSelEnd, hSourceTE);
  101.  
  102. // Move the text from the documents TERec and add the style (got above) to it
  103.     HLock((Handle)((*hSourceTE)->hText));
  104.     TEStyleInsert ( (Ptr)*((*hSourceTE)->hText),
  105.                                     (*hSourceTE)->teLength,
  106.                                     printerTextStyles,
  107.                                     *hDestTE);        
  108.     HUnlock((Handle)((*hSourceTE)->hText));
  109.  
  110. // Deactivat the temporary TERec
  111.     TEDeactivate(*hDestTE);
  112.     
  113. // Reset the port
  114.     SetPort(oldPort);
  115. }
  116.  
  117.